package com.offcn.service;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.util.ArrayList;
import java.util.List;

public class BloomFilterService {


    public static void main(String[] args) {
        int total = 1000000;
        //初始化布隆过滤器
        BloomFilter<Integer> bf = BloomFilter.create(Funnels.integerFunnel(), total,0.1);
        //初始化数据到布隆过滤器中
        for (int i = 0; i < total; i++) {
            bf.put(i);
        }

        //判断值是否存在在布隆过滤器中
        int count = 0;
        for (int i = 0; i < total + 10000; i++) {
            if (bf.mightContain(i)) {
                count++;
            } else{
                System.out.println("没有匹配上的数字" + i);
            }
        }
        System.out.println("已经匹配的数量" + count);
        System.out.println("没有匹配上的数量" + (total+10000-count));
    }
}